package cn.kgc.layui.service.impl;

import cn.kgc.layui.dao.RoleDao;
import cn.kgc.layui.dao.StudentDao;
import cn.kgc.layui.dao.impl.RoleDaoImpl;
import cn.kgc.layui.dao.impl.StudentDaoImpl;
import cn.kgc.layui.entity.Role;
import cn.kgc.layui.entity.Student;
import cn.kgc.layui.service.RoleService;
import cn.kgc.layui.service.StudentService;
import cn.kgc.layui.util.LayUiResult;

import java.util.List;

/**
 * 学生物实现类
 * @author alex-ycp
 * @create 2021-07-16 15:43
 */
public class RoleServiceImpl implements RoleService{

    private RoleDao roleDao = new RoleDaoImpl();

    @Override
    public LayUiResult<Role> findByPage(int start, int size, Role role) {

        List<Role> students = roleDao.findAllByPage(start, size,role);
        long count = roleDao.selectTotalCount();

        LayUiResult<Role> layUiResult = LayUiResult.<Role>builder().code(0).msg("请求成功").count(count).data(students).build();

        return layUiResult;
    }

    @Override
    public int save(Role role) {
        int result=0;
        try {
            result=roleDao.save(role);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;


    }

    @Override
    public int update(Role role) {
        int result=0;
        try {
            result=roleDao.update(role);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int delete(String id, String ids) {
        int result=0;
        try {
            if(null!=id&&id.length()>0){
                result=roleDao.delete(id);
            }else{
                String [] idArra= ids.split(",");
                for (String myId:idArra) {
                    result=roleDao.delete(myId);
                }
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }
}
